from typing import List, Dict, Any


class DynamicDataBuilder:
    """动态数据构建器"""

    def __init__(self):
        self.fields = []

    def add(self, field_name: str, field_type: str, value: str) -> None:
        """添加字段"""
        self.fields.append({
            "field_name": field_name,
            "field_type": field_type,
            "value": value
        })

    def build(self) -> List[Dict[str, Any]]:
        """构建最终数据格式"""
        dynamic_data = []
        for field in self.fields:
            dynamic_data.append({
                "name": field["field_name"],
                "type": field["field_type"],
                "data": field["value"]
            })
        return dynamic_data

    def clear(self) -> None:
        """清空字段"""
        self.fields.clear()


# app = Flask(__name__)
#
#
# @app.route('/api/dynamic-data')
# def get_dynamic_data():
# builder = DynamicDataBuilder()
#
# # 动态添加数据
# builder.add("name属性", FieldType.TEXT.value, "12345")
# builder.add("name", FieldType.TEXT.value, "12345")
# builder.add("description", "textarea", "这是一个测试描述信息")
#
# print(builder.build())

